package controller

import (
	"gdfs-center/controller/vo"
	"gdfs-center/db"
	"gdfs-center/utils"
	"github.com/gin-gonic/gin"
)

func GetSysteminfo(c *gin.Context) {
	c.Writer.Header().Set("content-type", "application/json")
	var svo vo.SystemInfoVo
	cpuPercent, cpuCount, cpuGhz := utils.GetCpuInfo()
	mPercent, mtotal, mused := utils.GetMemInfo()
	dPercent, dtotal, dused := utils.GetDiskInfo()
	sPercent, stotal, sused := utils.GetSwapInfo()
	var total int64 = 0
	var nodetotal int64 = 0
	var storetotal int64 = 0
	var sinfos []db.SystemInfo
	var nodes []db.Node
	var stores []db.Store
	db.GetDB().First(&stores).Count(&storetotal)
	db.GetDB().Find(&nodes).Count(&nodetotal)
	db.GetDB().Find(&sinfos)
	for _, s := range sinfos {
		total = total + s.StoreFileCount
	}
	svo.CpuGhz = cpuGhz
	svo.CpuPercent = cpuPercent
	svo.CpuCount = cpuCount
	svo.DiskTotal = int64(dtotal)
	svo.DiskPercent = dPercent
	svo.DiskUsed = int64(dused)
	svo.MemUsed = int64(mused)
	svo.MemTotal = int64(mtotal)
	svo.MemPercent = mPercent
	svo.SwapUsed = int64(sused)
	svo.SwapTotal = int64(stotal)
	svo.SwapPercent = sPercent
	svo.FileTotal = total
	svo.NodeTotal = nodetotal
	svo.StoreTotal = storetotal
	WritedString(c.Writer, true, "0", "处理成功", svo)
}
